package com.dakor.catalog;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Spring-context container.
 *
 * @author Korobeynikov Dmitry
 * @version 1.0
 */
public class Context {
    /** spring-context */
    private static ApplicationContext context;

    /**
     * Get spring-context.
     * @return spring-context
     */
    public static ApplicationContext getContext() {
        if (context == null) {
            context = new ClassPathXmlApplicationContext("context.xml");
        }

        return context;
    }

    /**
     * Get spring-context bean.
     * @param clazz the class of getting bean
     * @param <T> the type of getting bean
     * @return the class of getting bean
     */
    public static <T> T getBean(Class<T> clazz) {
        return getContext().getBean(clazz);
    }

}
